package com.yiang.order.controller;

import com.yiang.base.R;
import com.yiang.order.entity.Order;
import com.yiang.order.service.OrderService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("/order")
@Tag(name = "订单服务")
@Slf4j
public class OrderController {

    @Value("${server.port}")
    private String port;
    @Autowired
    private OrderService orderService;

    @GetMapping("/test")
    @Cacheable(cacheNames = "Orders", key = "'test'")  //key和方法名对应 加''
    public void test() {
        List<Order> list = orderService.list();
        System.out.println(list);
    }

    /**
     * 新增
     * @param order
     * @return
     */
    @PostMapping("/saveOrder")
    //@Cacheable(cacheNames = "order", key = "#order.id")
    public R saveHotel(@RequestBody Order order) {
        orderService.save(order);
        return R.success("创建订单成功");
    }
}
